<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<%@include file="/res/include/umeditor.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/homemaking/dictType.js"></script>
  </head>
  <body>  
<div class="page_title clearfix">
    <h2>
    <c:if test="${!empty entity}">
    	编辑
    </c:if>
    <c:if test="${empty entity}">
    	新建
    </c:if>
    </h2>
</div>
<div class="form_item topic_add">
   <form id="data-form">
   	<c:if test="${!empty entity}">
    	<input type="hidden" name="id" value="${entity.id }"/>
    	<input type="hidden" name="code" value="${entity.code }"/>
    	<input type="hidden" name="type" value="${entity.type }"/>
    </c:if>
    <c:if test="${empty entity}">
    	<input type="hidden" name="code" value="${typeId }"/>
    </c:if>
    <dl>
        <dt>类型：</dt>
        <dd>
        	<c:if test="${!empty entity}">
        		${entity.typeDesc}
        	</c:if>
        	<c:if test="${empty entity}">
        		<select name="type" id="type">
				<option value="1"
					<c:if test="${entity != null && entity.type==1}"> selected="selected"</c:if>
				>服务标准</option>
				<option value="2"
					<c:if test="${entity != null && entity.type==2}"> selected="selected"</c:if>
				>服务流程</option>
				<option value="3"
					<c:if test="${entity != null && entity.type==3}"> selected="selected"</c:if>
				>服务说明</option>
			</select>
        	</c:if>
        </dd>
    </dl>
    <dl>
        <dt>内容：</dt>
        <dd>
        	<textarea id="name" class="field-remark easyui-validatebox" rows="5" cols="60" name="name" data-options="validType:'length[1,500]'">${entity.name}</textarea>
        	<font id="inputNum" color="red" size="5"></font>
        </dd>
    </dl>
    <dl>
       	<dt>图片：</dt>
           <dd>
           <c:if test="${empty entity}">
           	<ul class="product_imglist img_imglist">
            	<li><a href="javascript:;" class="item" id="pic1" onclick="admin.dictType.addImg('pic1')">添加图片</a></li>
                <li><a href="javascript:;" class="item" id="pic2" onclick="admin.dictType.addImg('pic2')">添加图片</a></li>
                <li><a href="javascript:;" class="item" id="pic3" onclick="admin.dictType.addImg('pic3')">添加图片</a></li>
                <li><a href="javascript:;" class="item" id="pic4" onclick="admin.dictType.addImg('pic4')">添加图片</a></li>
                <li><a href="javascript:;" class="item" id="pic5" onclick="admin.dictType.addImg('pic5')">添加图片</a></li>
                <li><a href="javascript:;" class="item" id="pic6" onclick="admin.dictType.addImg('pic6')">添加图片</a></li>
            </ul>
            </c:if>
            <c:if test="${!empty entity}">
            <ul class="product_imglist img_imglist">
           		<c:set var="imgCount" value="1" />
           		<c:forTokens items="${entity.remark}" delims=";" var="img" varStatus="status"> 
           			<c:set var="imgCount" value="${status.count}" />
           			<li>
           			<a href="javascript:;" class="item" id="pic${status.index+1}" onclick="admin.dictType.addImg('pic${status.index+1}')"><p class="img"><img src="http://file.xfquanquan.com${img }" alt="" /></p></a>
           			<em onclick="delPic(this,${status.index+1})"></em>
           			</li>
           		</c:forTokens>
           		<c:forEach begin="${imgCount}" end="6" step="1" varStatus="i">
           			<li><a href="javascript:;" class="item" id="pic${i.index+1+imgCount}" onclick="admin.dictType.addImg('pic${i.index+1+imgCount}')">添加图片</a></li>
           		</c:forEach>
            </ul>
            </c:if>
            <em class="p0">上传JPG/PNG/BMP图片，建议：200*120px</em>
           </dd>
       </dl>
    </form>
    <p class="page_btn" id="showBtn"><input type="button" id="doSave" value="保存" class="btn_blue" onclick="doSave();"/></p>
</div>
<script type="text/javascript">
function setImeisNum(e){
	 var count=0;
	 var myEvent = e || window.event;
	 var keycode =  myEvent.keyCode;
	 count = countImeis().length;
	 if(count >= 0){
		$("#inputNum").html("数量:"+count);
	 }
}

function countImeis(){
	var temp =$.trim($("#name").val());
   var resultArray =new Array();
	if(null != temp && "" != temp){
		var array = temp.split(/\r|\s|;/g);
		for (var i=0; i < array.length; i++) {
			if (null != array[i] && "" != array[i]) {
				resultArray.push(array[i]);
			}
		}
	}
   return resultArray;
}
$(document).ready(function() {
	$("#name").bind("keyup",setImeisNum);
});

var isSave = false;
//提交保存
function doSave(){
	var url = contextPath+'/homemaking/sys/dict/addDictType';
	<c:if test="${!empty entity}">
		url = contextPath+'/homemaking/sys/dict/updateDictType';
	</c:if>
	if(!$('#data-form').form('validate')) return;
	if (isSave) {
		return;
	}
	isSave = true;
	var img = "";
	var imglist = $(".img_imglist img");
	if (imglist && imglist.length > 0) {
		imglist.each(function(){
		    if (img == "") {
		    	img += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	img += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	}
	var data = $('#data-form').form('jsonObject');
	data.remark = img;
	//console.info("------------:"+JSON.stringify(data));
	$.post(url,data,function(result) {
		if(result.code==1) {
			top.showInfo('保存成功');
		} else {
			isSave = false;
			top.showInfo('保存失败:'+result.msg);
		}
	},'json');
}
function delPic(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="pic'+index+'" onclick="admin.dictType.addImg(\'pic'+index+'\')">添加图片</a>');
}
</script>
  </body>
</html>
